<% content_for :page_title do %>
  <%= Spree.t(:customer_returns) %>
<% end %>

<% content_for :table_filter do %>
  <div data-hook="admin_return_authorisations_index_filters">
    <%= search_form_for [:admin, @search], url: spree.admin_customer_returns_path do |f| %>
      <div class="row">
        <div class="col-12">
          <div class="form-group">
            <%= f.label :number_cont, Spree.t(:number) %>
            <%= f.text_field :number_cont, class: "form-control js-quick-search-target js-filterable" %>
          </div>
        </div>
      </div>
      <div data-hook="admin_return_authorisations_index_filters_buttons" class="form-actions">
        <%= button Spree.t(:search), 'search.svg' %>
      </div>
    <% end %>
  </div>
<% end %>

<% if @collection.any? %>
<div class="table-responsive">
  <table class="table">
    <thead>
      <tr data-hook="rate_header">
        <th><%= Spree.t(:created_at) %></th>
        <th><%= Spree.t(:number) %></th>
        <th><%= Spree.t(:order) %></th>
        <th><%= Spree.t(:reimbursement_status) %></th>
        <th><%= Spree.t(:pre_tax_total) %></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <% @collection.each do |customer_return| %>
        <tr id="<%= spree_dom_id customer_return %>" data-hook="customer_return_row">
          <td><%= customer_return.created_at.strftime('%F %T %Z') %></td>
          <td><%= link_to customer_return.number, spree.edit_admin_order_customer_return_path(customer_return.order, customer_return) %></td>
          <td><%= link_to customer_return.order.number, spree.edit_admin_order_path(customer_return.order) %></td>
          <td>
            <% if customer_return.fully_reimbursed? %>
              <span class="badge badge-success"><%= Spree.t(:reimbursed) %></span>
            <% else %>
              <span class="badge badge-info"><%= Spree.t(:incomplete) %></span>
            <% end %>
          </td>
          <td><%= customer_return.display_pre_tax_total.to_html %></td>
          <td class="actions actions-1 text-right">
            <%= link_to_edit_url spree.edit_admin_order_customer_return_path(customer_return.order, customer_return), no_text: true if can?(:edit, customer_return) %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>
<% else %>
  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::CustomerReturn)) %>.  </div>
<% end %>

<%= render partial: 'spree/admin/shared/index_table_options', locals: { collection: @collection, per_page_action: :customer_returns } %>
